/**
 * Copyright 2008 Frank van Lingen Licensed under the Apache License, Version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package superpodder.gui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;

/**
 * A dialog class that provides some help information for the user and explains
 * the xml feed format used.
 * 
 * @author fvlingen
 */

public class ContentsView extends JDialog {

    private static final long serialVersionUID = -8351768253997601744L;

    public ContentsView(JFrame parent) {
        super(parent, "Contents", true);
        System.out.println("Starting Contents Viewer");
        this.setMinimumSize(new Dimension(400, 200));
        this.setResizable(true);
        this.setSize(500, 400);

        // Allow to close but not exit the gui.
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                e.getWindow().setVisible(false);
            }
        });

        final GridBagLayout gridbag = new GridBagLayout();
        final GridBagConstraints gbc = new GridBagConstraints();

        this.setLayout(gridbag);
        
        // set external padding of components.
        gbc.insets = new Insets(2,2,2,2);
       
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.BOTH;
       
        // Message this dialog displays.
        final String msg = "This application manages downloads of (audio) feeds. The graphical frontend is mainly there to show the progress of the parallel streams. In the config file you can set the number of downloads and it will try to download the most recent episodes. E.g. if you define number is 3, then it will try and download the 3 most recent podcasts. The application works with 4 files."
                + " the config file (superPodder.cfg) is created if it is not available. This file contains several parameters that can be set in the settings window: \n\n"
                + " -History file which keeps track of the downloaded files (to prevent duplicate downloads)\n"
                + " -Log file which shows log messages of the last download session\n"
                + " -Feeds file which contains the urls from which you want to download\n"
                + " -A directory that specifies the output directory for the downloaded feeds\n"
                + " -A number that specifies the number of parallel downloads \n"
                + " -A checkbox to activate the torrent link\n"
                + " -A reference that points to the torrent client, used when activated\n\n"
                + "In order to use the torrent link, a torrent client needs to be installed and accepting torrent feeds in command line mode. If the torrent client is set up, the SuperPodder client will delegate torrent urls that it identifies in the rss feed to this client for distributed downloads\n\n"
                + "The reason for working with text files that you that it enables you to migrate your feeds to another application if necessary and makes it easy to share them with friends. It also makes it easier to import feeds from another application by using your favorite editor (e.g. VI, Emacs, ...) without clicking your way through an elaborate user interface.\n\n"
                + "The xml to format the feeds is kept simple for editing purposes. There are 3 levels in the hierarchy: main tag, group tag, and feed tag. The group tag enables you to group feeds together in a logical group (e.g.)"
                + " 'science' or 'documentary'. The feed tag contains the actual feed url and a number that specifies how many downloads you want as some programs are cut"
                + " into multiple mp3 snippets. The files are written to the directory <output directory>/<group>/<feed name>. "
                + "Below an example of how such a file looks like. If you make a typo the application will show "
                + " a dialog with the error. Included in the distribution is also an example file with my feeds. Make sure that you escape characteres where needed e.g. & becomes &amp; \n\n\n"
                + "<Feeds>\n"
                + "   <Group name=\"science\">\n"
                + "       <Feed name=\"quirks_and_quarks\" number=\"4\" url=\"http://some.where...\"/>\n"
                + "       <Feed name=\"science_friday\" number=\"1\" url=\"http://some.where.else..\"/>\n"
                + "   ......\n"
                + "   </Group>\n"
                + "   <Group name=\"technology\">\n"
                + " .........\n"
                + "</Feeds>\n\n\n"
                + "The buttons in the menu bar are self explanatory, except maybe for 'download size'."
                + "'download size' will estimate the amount being downloaded. During downloading, color coding shows the progress, success and failures of the various feeds."
                + "\n\nFrank van Lingen 2010\n" + "http://vanlingen.name";
        final JTextArea textArea = new JTextArea(msg, 40, 50);
        Font font = new Font("Verdana", Font.BOLD, 12);
        textArea.setFont(font);
        textArea.setEditable(false);
        textArea.setLineWrap(true);

        final JScrollPane scrollPane = new JScrollPane(textArea,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        
        gridbag.setConstraints(scrollPane, gbc);
        this.add(scrollPane);

    }
}
